package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.dto.UrlLinkDTO;
import com.ruoyi.system.utils.WeChatUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Api(description = "微信")
@RestController
@RequestMapping("/wechat")
public class WeChatController {

    @Resource
    private WeChatUtil weChatUtil;

    @ApiOperation("获取加密URLLink")
    @GetMapping("/generateUrlLink")
    public AjaxResult generateUrlLink() throws WxErrorException {
        String urlLink = weChatUtil.generateUrlLink("/other/staff/staffEdit", "id=123465");
        String urlLink2 = weChatUtil.generateUrlLink("/other/gwnotice/gwnoticeForm", "id=" + "1" +"&userId=" + "2");
        Map<String,String> map = new HashMap<>();
        map.put("staff",urlLink);
        map.put("gwnotice",urlLink2);
        return AjaxResult.success(map);
    }

    @ApiOperation("查询加密URLLink")
    @PostMapping("/queryUrlLink")
    public AjaxResult queryUrlLink(@Validated @RequestBody UrlLinkDTO urlLinkDTO) {
        String res = weChatUtil.queryUrlLink(urlLinkDTO.getUrl(), 0L);
        return AjaxResult.success(res);
    }

}
